home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Feb
/
di9802am
/
ConfZipU.pas
Wrap
Pascal/Delphi Source File
|
1997-10-02
|
4KB
|
127 lines
{Listing 1}
unit ConfZipU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, AbZipper, AbArcTyp, AbZBrows, AbUnZper;
type
TForm1 = class(TForm)
Memo1: TMemo;
Label1: TLabel;
EncryptAndCompressBtn1: TBitBtn;
DecryptAndDecompressBtn1: TBitBtn;
BitBtn1: TBitBtn;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
AbUnZipper1: TAbUnZipper;
AbZipper1: TAbZipper;
procedure EncryptAndCompressBtn1Click(Sender: TObject);
procedure DecryptAndDecompressBtn1Click(Sender: TObject);
private
{ Private declarations }
EncryptPassword : string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Abdlgpwd, LbProc, LbCipher;
{$R *.DFM}
procedure TForm1.EncryptAndCompressBtn1Click(Sender: TObject);
var
Dlg : TPassWordDlg;
Key : TKey128;
EncryptedFile : string;
begin
if (Memo1.text='') then
begin
MessageDlg('You haven''t entered any text to save', mtError,
[mbOK], 0);
exit;
end;
Dlg := TPassWordDlg.Create(Application);
EncryptPassword := '';
try
Dlg.ShowModal;
if Dlg.ModalResult = mrOK then
EncryptPassword := Dlg.Edit1.Text;
finally
Dlg.Free;
end;
if EncryptPassword = '' then exit;
ChDir(ExtractFilePath(Application.ExeName));
SaveDialog1.Title := 'Enter Name of Text File to Archive';
SaveDialog1.Filter := 'Text files (*.txt)|*.TXT';
if SaveDialog1.Execute then
begin
if Pos('.', SaveDialog1.FileName)=0 then
SaveDialog1.FileName := concat(SaveDialog1.FileName, '.txt');
try
Memo1.Lines.SaveToFile(ChangeFileExt(SaveDialog1.FileName, '.txt'));
finally { wrap up }
end; { try / finally }
with AbZipper1 do
begin
BaseDirectory := ExtractFilePath(SaveDialog1.FileName);
AbZipper1.Filename := ChangeFileExt(SaveDialog1.FileName, '.zip');
EncryptedFile := ChangeFileExt(SaveDialog1.FileName, '.xxx');
GenerateLMDKey(Key, SizeOf(Key), EncryptPassword);
LBCEncryptFile(SaveDialog1.FileName, EncryptedFile, Key, 16, True);
AddFiles(SaveDialog1.FileName, 0);
Save;
end; { with }
If MessageDlg('Delete Text File?', mtConfirmation, [mbOK, mbCancel], 0)
=idOK then DeleteFile(ChangeFileExt(SaveDialog1.FileName, '.txt'));
end;
end;
procedure TForm1.DecryptAndDecompressBtn1Click(Sender: TObject);
var
TextFile : string;
Dlg : TPassWordDlg;
Key : TKey128;
EncryptedFile : string;
begin
Dlg := TPassWordDlg.Create(Application);
EncryptPassword := '';
try
Dlg.ShowModal;
if Dlg.ModalResult = mrOK then
EncryptPassword := Dlg.Edit1.Text;
finally
Dlg.Free;
end;
if EncryptPassword = '' then exit;
OpenDialog1.Title := 'Open Zip File';
OpenDialog1.Filter := 'Zip files (*.zip)|*.ZIP';
if OpenDialog1.Execute then
begin
TextFile := ExtractFileName(ChangeFileExt(OpenDialog1.FileName, '.txt'));
EncryptedFile := ChangeFileExt(OpenDialog1.FileName, '.xxx');
with AbUnZipper1 do
begin
BaseDirectory := ExtractFilePath(OpenDialog1.FileName);
ChDir(BaseDirectory);
Filename := OpenDialog1.FileName;
ExtractFiles(EncryptedFile);
GenerateLMDKey(Key, SizeOf(Key), EncryptPassword);
LBCEncryptFile(EncryptedFile, TextFile, Key, 16, False);
end; { with }
try
Memo1.Lines.LoadFromFile(TextFile);
finally
end;
end;
end;
end.